# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=lcms2
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.7
pkgrel=1
pkgdesc="Small-footprint color management engine, version 2 (mingw-w64)"
arch=('any')
url="http://www.littlecms.com"
license=("MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-libtiff")
options=('staticlibs' 'strip')
source=("https://downloads.sourceforge.net/sourceforge/lcms/lcms2-${pkgver}.tar.gz"
        0001-fix-testcmd2.mingw.patch
        0002-need-jconfig-before-jmoreconfig.mingw.patch
        0003-install-mans.all.patch)
sha256sums=('4524234ae7de185e6b6da5d31d6875085b2198bc63b1211f7dde6e2d197d6a53'
            'c9b52864f0a62514537be9882f81ebd73f59acb4486bd0acb5ff21936ae7f569'
            '3e85375a6b38de36e19fa7b4415b8c86aff492c0ef625932bec073d45e944339'
            '1a441261bc6f2adc4eebfd3b816b2e9cbc98014e419a53845d0e6a6243471825')

prepare() {
  cd ${_realname}-$pkgver
  patch -p1 -i ${srcdir}/0001-fix-testcmd2.mingw.patch
  patch -p1 -i ${srcdir}/0002-need-jconfig-before-jmoreconfig.mingw.patch
  patch -p1 -i ${srcdir}/0003-install-mans.all.patch

  autoreconf -fiv
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  cp -rf ${srcdir}/${_realname}-${pkgver} "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  ./configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --enable-shared \
    --enable-static

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
